/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.paymenttag;

import com.apt.bean.Payments;
import com.apt.tag.Connect_DB;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

/**
 *
 * @author Bach
 */
public class GetPayments {

    public static HashMap<Integer, Payments> getListPayment() {
        HashMap<Integer, Payments> listP = new HashMap<Integer, Payments>();
        PreparedStatement ps = null;
        ResultSet rs = null;
        Connection conn = null;
//        where Payment_Type_Status=1
        String query = "SELECT  [Payment_Type_Id] ,[Payment_Type_Status],[Payment_Type_Name] FROM [Matrimony].[dbo].[Payment_Types]  ";
        try {
            conn = Connect_DB.getConnection();
            if (conn != null) {
                ps = conn.prepareStatement(query);
                rs = ps.executeQuery();
                int key = 1;
                String payment_Type_Id;
                String payment_Type_Status;
                String payment_Type_Name;
                while (rs.next()) {
                    payment_Type_Id = rs.getString("Payment_Type_Id");
                    payment_Type_Status = rs.getString("Payment_Type_Status");
                    payment_Type_Name = rs.getString("Payment_Type_Name");
                    Payments p = new Payments(payment_Type_Id, payment_Type_Status, payment_Type_Name);
                    listP.put(key, p);
                    key++;
                }
            } else {
                System.out.println("Connect is null");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Connect_DB.close(rs, null, ps, conn);
        }
        return listP;
    }
}
